using System.Collections.Generic;
using System.IO;
using System.Xml;

namespace ICSharpCode.TextEditor.Document
{
	public class SyntaxMode
	{
		private string fileName;

		private string name;

		private string[] extensions;

		public string FileName
		{
			get
			{
				return this.fileName;
			}
			set
			{
				this.fileName = value;
			}
		}

		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}

		public string[] Extensions
		{
			get
			{
				return this.extensions;
			}
			set
			{
				this.extensions = value;
			}
		}

		public SyntaxMode(string fileName, string name, string extensions)
		{
			this.fileName = fileName;
			this.name = name;
			this.extensions = extensions.Split(';', '|', ',');
		}

		public SyntaxMode(string fileName, string name, string[] extensions)
		{
			this.fileName = fileName;
			this.name = name;
			this.extensions = extensions;
		}

		public static List<SyntaxMode> GetSyntaxModes(Stream xmlSyntaxModeStream)
		{
			XmlTextReader xmlTextReader = new XmlTextReader(xmlSyntaxModeStream);
			List<SyntaxMode> list = new List<SyntaxMode>();
			while (xmlTextReader.Read())
			{
				XmlNodeType nodeType = xmlTextReader.NodeType;
				XmlNodeType xmlNodeType = nodeType;
				if (xmlNodeType != XmlNodeType.Element)
				{
					continue;
				}
				string text = xmlTextReader.Name;
				string text2 = text;
				if (!(text2 == "SyntaxModes"))
				{
					if (!(text2 == "Mode"))
					{
						throw new HighlightingDefinitionInvalidException("Unknown node in syntax mode file :" + xmlTextReader.Name);
					}
					list.Add(new SyntaxMode(xmlTextReader.GetAttribute("file"), xmlTextReader.GetAttribute("name"), xmlTextReader.GetAttribute("extensions")));
				}
				else
				{
					string attribute = xmlTextReader.GetAttribute("version");
					if (attribute != "1.0")
					{
						throw new HighlightingDefinitionInvalidException("Unknown syntax mode file defininition with version " + attribute);
					}
				}
			}
			xmlTextReader.Close();
			return list;
		}

		public override string ToString()
		{
			return string.Format("[SyntaxMode: FileName={0}, Name={1}, Extensions=({2})]", this.fileName, this.name, string.Join(",", this.extensions));
		}
	}
}
